package com.nuaa.controller.admin;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nuaa.controller.base.BaseController;
import com.nuaa.domain.user.admin.AdminInfo;
import com.nuaa.service.inter.AdminInfoServiceInter;
import com.nuaa.utils.AjaxMsg;
import com.nuaa.utils.EcodeByMD5;
import com.nuaa.utils.SessionKey;

@Controller
@RequestMapping("admin/basic")
public class BasicController extends BaseController {
	
	@Autowired
	private AdminInfoServiceInter adminInfoService;
	
	
	@RequestMapping("update_password")
	public void updatePassword(String originalPassword,String login_password,HttpSession session,HttpServletResponse response){
		AjaxMsg msg = new AjaxMsg();
		AdminInfo adminInfo= (AdminInfo) session.getAttribute(SessionKey.UserInfoKey);
		String originalpass = EcodeByMD5.ecodeByMD5(originalPassword);
		if(adminInfo.getLogin_password().equals(originalpass))
		{
			adminInfo.setLogin_password(EcodeByMD5.ecodeByMD5(login_password));
			try{
				adminInfoService.update(adminInfo);
				msg.setMsg("更新成功！");
				msg.setSuccess(true);
				session.setAttribute(SessionKey.UserInfoKey, adminInfo);
			}catch(Exception e){
				msg.setMsg("更新发生异常");
				msg.setSuccess(false);
			}
		}else {
			msg.setMsg("当前密码输入不正确！");
			msg.setSuccess(false);
		}
		this.writeJson(response, msg);
	}
}
